﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.Data;


using Common;

using Castle.Core.Interceptor;
using Castle.DynamicProxy;

namespace com.globalwave.a8ext
{
    public class FeePayoutService : BaseService
    {
        private static NameValueCollection whereMap = null;
        private const string TABLE_NAME = "Fee_Payout";

        
        public FeePayoutService()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public FeePayoutService(BaseService other)
            : base(other) 
        {
        }

        virtual public int create(NameValueCollection entity)
        {
            return dao.insertTable(TABLE_NAME, entity);
        }

        virtual public int update(NameValueCollection entity)
        {
            NameValueCollection criterion = new NameValueCollection();
            string id = entity.Get("id_");

            criterion.Add("id_", id);

            entity.Remove("id_");

            int result = dao.updateTable(TABLE_NAME, entity, criterion);

            entity.Add("id_", id);

            return result;
        }

        virtual public int delete(NameValueCollection criterion)
        {
            if (criterion.Get("id_") != null)
            {
                throw new BaseException("E000001", "参数错误");
            }
            // delete cascade 
            //dao.deleteTable(TABLE_BULLETIN, criterion);
            //dao.deleteTable(TABLE_TOPIC, criterion);

            return dao.deleteTable(TABLE_NAME, criterion);

        }

        virtual public void deleteAll(string[] ids)
        {
            if (ids == null || ids.Length == 0)
            {
                throw new BaseException("", "parames");
            }

            NameValueCollection criterion = new NameValueCollection();
            foreach (string id in ids)
            {
                criterion.Add("ids", id);
            }

            // delete cascade
            //dao.deleteTable(TABLE_BULLETIN, criterion);
            //dao.deleteTable(TABLE_TOPIC, criterion);

            dao.deleteTable(TABLE_NAME, criterion);

        }

        public NameValueCollection getWhereConfigMap()
        {
            if (whereMap != null)
            {
                return whereMap;
            }

            whereMap = new NameValueCollection();

            whereMap.Add("ids", " id_ in (@ids) ");
            //whereMap.Add("FullName", " FullName like ? ");
            //whereMap.Add("UserCode", " UserCode like ? ");

            return whereMap;
        }

        public static FeePayoutService getInstance()
        {

            ProxyGenerator generator = new ProxyGenerator();

            return generator.CreateClassProxy<FeePayoutService>(new TransactionInterceptor());

        }
    }
}
